package org.fuxian.service.impl;

import org.fuxian.dao.MyAreaMapper;
import org.fuxian.domain.MyArea;
import org.fuxian.service.IMyAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MyAreaServiceImpl  implements IMyAreaService {

    @Autowired
    MyAreaMapper areaMapper;

    @Override
    public MyArea findById(int aid) {
        return areaMapper.findById(aid);
    }

    @Override
    public List<MyArea> findAll() {
        return areaMapper.findAll();
    }

    @Override
    public MyArea findAreaByName(String aname) {
        return areaMapper.findByName(aname);
    }

    @Override
    public int add(String aname) {
        return areaMapper.add(aname);
    }

    @Override
    public int update(String aname, int aid) {
        return areaMapper.update(aname,aid);
    }

    @Override
    public int delete(int aid) {
        int count = 0;
        try {
            count = areaMapper.delete(aid);
        } catch (Exception e) {
            //外键约束
            count = -1;
            e.printStackTrace();
            System.err.println(e.getMessage() + "\n" + "请先删除该类别的房屋");
        }
        return count;
    }
}
